﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using MedicWeb.MedicService;

namespace MedicWeb.forms {
    public partial class DirectorySimpleList : SessionPage {
        protected void Page_Load(object sender, EventArgs e) {
            string directory = Request.QueryString["directory"];
            var ms = new MainService();
            DirectorySimpleItem[] items;
            switch (directory) {
                case "AcademicTitle": {
                        items = ms.GetAcademicTitleList(GetSession(), false);
                        break;
                    }
                case "Class": {
                        items = ms.GetClassList(GetSession(), false);
                        break;
                    }
                case "ClassSpecialisation": {
                        items = ms.GetClassSpecialisationList(GetSession(), false);
                        break;
                    }
                case "InstitutionType": {
                        items = ms.GetInstitutionTypeList(GetSession(), false);
                        break;
                    }
                case "Degree": {
                        items = ms.GetDegreeList(GetSession(), false);
                        break;
                    }
                case "JobCategory": {
                        items = ms.GetJobCategoryList(GetSession(), false);
                        break;
                    }
                case "Ownership": {
                        items = ms.GetOwnershipList(GetSession(), false);
                        break;
                    }
                case "Region": {
                        items = ms.GetRegionList(GetSession(), false);
                        break;
                    }
                default: {
                        throw new DataException();
                    }
            }
            hlAdd.NavigateUrl = ResolveUrl("~/forms/Editors/Directory/Simple/SimpleEdit.aspx?directory=" + directory);
            foreach (var item in items) {
                var tableRow = new TableRow();
                var cellEdit = new TableCell();
                cellEdit.Controls.Add(new HyperLink() {
                    CssClass = "edit modal",
                    NavigateUrl = ResolveUrl("~/forms/Editors/Directory/Simple/SimpleEdit.aspx?directory=" + directory + "&id=" + item.Id)
                });
                cellEdit.Width = 24;
                var cellId = new TableCell() { Text = "" + item.Id };
                var cellTitle = new TableCell() { Text = item.Title };
                tableRow.Cells.Add(cellEdit);
                tableRow.Cells.Add(createDeleteCell(item));
                tableRow.Cells.Add(cellId);
                tableRow.Cells.Add(cellTitle);
                tblDirectorySimple.Rows.Add(tableRow);
            }
        }
    }
}